#include "lexer.h"
#include <fstream>
#include <iostream>
#include <cctype>

class Tokenizer : public Lexer<21u>
{
	std::ifstream inputStream_;
public:
	Tokenizer();
	void print();
};

Tokenizer::Tokenizer() : inputStream_("sample.txt", std::ios::binary | std::ios::in)
{
}

void Tokenizer::print()
{
	enum { WORD, SPACE } state = SPACE;
	int c = 0;
	int displayed = 1;

	while (c != EOF) {
		c = inputStream_.get();
		switch (state) {
		case WORD:
			displayed = 0;
			if (isspace(c) != 0) {
				displayed = 0;
				state = SPACE;
			} else if (c == EOF)
				std::cout << getLastLexeme();
			else
				addCharToLexeme(c);
			break;
		case SPACE:
			if (displayed == 0) {
				std::cout << getLastLexeme() << ' ';
				displayed = 1;
			}
			if (isspace(c) == 0) {
				inputStream_.putback(c);
				resetLexeme();
				state = WORD;
			}
			break;
		}
	}
}

int main()
{
	Tokenizer tokenizer;

	tokenizer.print();
	return 0;
}

